import request from '@/utils/request'
import { hexMD5 } from '@/utils/md5'

import variable from '@/utils/variables'
const baseURL = variable.URL.baseURL


export function login(pwForm, codeForm, loginActive) {
  if (loginActive == 0) {
    return request({
      baseURL: baseURL,
      url: '/auth/login',
      method: 'post',
      headers: {
        'Authorization': variable.VAR.defaultToken
      },
      params: {
				username: pwForm.username,
				password: hexMD5(pwForm.password+'yhby'),
			}
    })
  }else if (loginActive == 1) {
    return request({
      baseURL: baseURL,
      url: '/auth/mobile',
      method: 'POST',
      headers: {
        'Authorization': variable.VAR.defaultToken
      },
      params: {
				mobile: codeForm.mobile,
				smsValidateCode: codeForm.smsValidateCode,
			}
    })
  }
}

// 注册 发送验证码
export function registerSendCode(params) {
	return request({
	    baseURL: baseURL,
	    url: '/member/send_code',
	    method: 'POST',
      params: params
	})
}

// 注册
export function registerMember(params) {
	return request({
	    baseURL: baseURL,
	    url: '/member/register',
	    method: 'POST',
      params: params
	})
}

// 验证码登录 获取验证码
 export function getSendSms(params) {
   return request({
     baseURL: baseURL,
     url: '/auth/sendSms',
     method: 'POST',
     params: params
   })
 }

// 验证码登录
export function codeLogin(params) {
	return request({
		baseURL: baseURL,
		url: '/auth/mobile',
		method: 'POST',
		params: params
	})
}

// 获取用户信息
export function getInfo() {
  return request({
    baseURL: baseURL,
    url: '/member/center_info',
    method: 'get',
  })
}

// 退出登录
export function logout(token) {
  console.log(token)
}
